/******************************************************************************
 * Name: MemoryManager.h
 * Author: ZhengJuyu
 * Date: 2007/08/25
 * Revision: 
 *
 * Description:
 * This calss manages the memory space. It could provide executable memory space 
 * for the translated code.
 *
 *****************************************************************************/

#ifndef MEMORYMANAGER_H
#define MEMORYMANAGER_H

#include "crossbit/common.h"
#define ELEMENT_NUM 16

namespace crossbit
{
    class MemoryManager
    {
        public:
            ~MemoryManager();

            static MemoryManager* getInstance();
            // require a block of executable memory space
            XTMemAddr allocateExecutable(XTUint32 size);

            XTMemAddr allocateObjectPool(XTUint32 * pool_id, XTUint32 pool_size, XTUint32 obj_size);

            XTMemAddr allocateObject(XTUint32 obj_id, XTUint32 size );

        protected:
            MemoryManager();

        private:
            // 
            static MemoryManager* instance;

            XTMemAddr pool_exe;
            XTUint32 size_exe;
            XTMemAddr pool;
            XTUint32 size;
            XTMemAddr ele_pool[ELEMENT_NUM];
            XTUint32 ele_size[ELEMENT_NUM];
            XTInt32 ele_curr_ubound;
            // the start of the executable memory space
            static const XTMemAddr POOL_START_EXE = 0xA0000000;
            //128M pool capacity 
            static const XTUint32 POOLSIZE_EXE = 0x2000000;

            // the start of the read/write memory space
            static const XTMemAddr POOL_START = 0xA2000000;

            static const XTUint32 POOLSIZE = 0x6000000;
    };
}

#endif	//MEMORYMANAGER_H
